package com.aaa.dem1102.d04;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/11/2  15:56
 */
public class Test {
    public static void main(String[] args) {
        /*
        int corePoolSize, 核心线程的个数
      int maximumPoolSize, 最大线程的个数
      long keepAliveTime, 线程对象空闲的时间
      TimeUnit unit, 空闲时间单位
      BlockingQueue<Runnable> workQueue：等待队列
         */
        ThreadPoolExecutor executorService=new ThreadPoolExecutor(3,5,
                2000, TimeUnit.SECONDS,new LinkedBlockingDeque());
        //往线程池中提交任务。
        for(int i=0;i<30;i++){
            final int a=i;
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"~~~~~~"+a);
                }
            });
        }
    }
}
